<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app {
            padding: 10px;
            margin: 0 auto;
            width: 50%;
        }

        ul {
            list-style: none;
            width: 300px;
            padding: 10px;
            background-color: #ddd;
            border-radius: 5px;
            overflow: hidden;
            display: none;
        }

        li {
            float: left;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <button class="btn">点击显示</button>
        <ul>
            <li>中文</li>
            <li>英语</li>
            <li>日语</li>
            <li>韩语</li>
            <li>葡萄牙语</li>
            <li>法语</li>
            <li>西班牙语</li>
            <li>德语</li>
            <li>俄语</li>
            <li>泰语</li>
            <li>阿拉伯语</li>
            <li>粤语</li>
            <li>文言文</li>
            <li>荷兰语</li>
            <li>希腊语</li>
            <li>中文繁体</li>
            <li>匈牙利语</li>
            <li>意大利语</li>
        </ul>
    </div>
</body>
<script>
    let btn = document.querySelector('.btn')
    let ul = document.querySelector('#app ul')
    //绑定三个点击事件
    btn.addEventListener("click", function (e) {
        ul.style.display = 'block'
        //阻止事件冒泡
        let eventObj = e || event
        if (eventObj.stopPropagation) {
            eventObj.stopPropagation()
        } else {
            eventObj.cancelBubble()
        }
    }, false)
    ul.addEventListener("click", function (e) {
        ul.style.display = 'block'
        let eventObj = e || event
        if (eventObj.stopPropagation) {
            eventObj.stopPropagation()
        } else {
            eventObj.cancelBubble()
        }
    }, false)
    //document点击时ul隐藏
    document.addEventListener("click", function (e) {
        ul.style.display = 'none'
    }, false)
</script>

</html>